package com.example.comitclx1.controller;

import com.example.comitclx1.anno.Log;
import com.example.comitclx1.pojo.Dept;
import com.example.comitclx1.pojo.Result;
import com.example.comitclx1.service.DeptStrvice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {
    /**
     * 查询所有部门数据
     */
    @Autowired
    private DeptStrvice deptStrvice;
    @GetMapping
    public Result list(){
        return Result.success(deptStrvice.list());
    }
    /**
     * 删除操作
     */
    @Log
    @DeleteMapping("/{id}")
    private Result delete(@PathVariable Integer id){
        deptStrvice.delete(id);
        return Result.success();
    }
    /**
     * 新增部门
     */
    @Log
    @PostMapping
    private Result add(@RequestBody Dept dept){
        log.info("添加部门");
        deptStrvice.add(dept);
        return Result.success();
    }
    /**
     * 根据id查询
     */
    @GetMapping("/{id}")
    private Result getById(@PathVariable Integer id){
        Dept dept= deptStrvice.getById(id);
        return Result.success(dept);
    }
    /**
     * 修改部门
     */
    @Log
    @PutMapping
    private Result put(@RequestBody Dept dept){
        log.info("修改部门了");
        deptStrvice.put(dept);
        return Result.success();
    }
}
